package com.hellpro.lolbox.home.model;

import android.content.Context;

import com.hellpro.lolbox.bean.ZXSS;
import com.hellpro.lolbox.bean.ZXTT;
import com.hellpro.lolbox.bean.ZXZp;
import com.hellpro.lolbox.home.HomeJsonUtils;
import com.hellpro.lolbox.utils.OkHttpClientUtils;

import org.greenrobot.eventbus.EventBus;

import java.io.IOException;

/**
 * Package_Name: com.hellpro.lolbox.home.model
 * Description :对VpdeFragment的list下载
 *                            优化  把gson解析和下载解耦这样可以提取方法
 * author: HellPermanent
 * date:  2016/10/20 21:38
 * remarks：
 */
public class ZXModel implements IZXModel {
    private Context mContext;
 public  ZXModel(Context context){
     mContext = context;
 }


    @Override
    public void loadZXTTData(final String url, final int page) {
        new Thread(
                new Runnable() {
                    @Override
                    public void run() {
                        String path = url+page;
                        try {
                            String json = OkHttpClientUtils.getStringFromURL(mContext, path, null);
                            ZXTT data = HomeJsonUtils.getData(json, ZXTT.class);
                            EventBus.getDefault().post(data);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
        ).start();
    }

    @Override
    public void loadZXSSData(final String url , final int page) {
        new Thread(
                new Runnable() {
                    @Override
                    public void run() {
                        String path = url+page;
                        try {
                            String json = OkHttpClientUtils.getStringFromURL(mContext, path, null);
                            ZXSS data = HomeJsonUtils.getData(json, ZXSS.class);
                            EventBus.getDefault().post(data);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
        ).start();
    }

    @Override
    public void loadZXZPData(final String url, final int page) {

        new Thread(
                new Runnable() {
                    @Override
                    public void run() {
                        String path = url+page;
                        try {
                            String json = OkHttpClientUtils.getStringFromURL(mContext, path, null);
                            ZXZp data = HomeJsonUtils.getData(json, ZXZp.class);
                            EventBus.getDefault().post(data);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
        ).start();
    }
}
